package cn.tta.controller.user;

import cn.tta.common.constant.StatusConstant;
import cn.tta.common.result.Result;
import cn.tta.pojo.entity.Setmeal;
import cn.tta.pojo.vo.DishItemVO;
import cn.tta.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
@Slf4j
public class UserSetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 条件查询
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmeanCache", key = "#categoryId")
    public Result list(Long categoryId) {
        Setmeal build = Setmeal.builder().categoryId(categoryId).status(StatusConstant.ENABLE).build();
        List<Setmeal> list = setmealService.list(build);
        return Result.success(list);
    }

    @GetMapping("/dish/{id}")
    public Result dishList(@PathVariable Long id) {
        List<DishItemVO> list = setmealService.getDishItemById(id);
        return Result.success(list);
    }


}
